package com.szosen.jkzj.activity.mbgy;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.szosen.database.DBService;
import com.szosen.database.VisitPlan;
import com.szosen.jkzj.R;
import com.szosen.jkzj.activity.BaseActivity;
import com.szosen.json.JsonUtil;
import com.szosen.json.database.ArchiveBean;
import com.szosen.json.database.JSONDBService;

import org.json.JSONException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class MBGY_Main extends BaseActivity {
    private Button hypbtn;
    private Button glybtn;

    private Intent intent;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.health_help);
        super.setTitleContent("【慢病干预】");
        findView();
        setOnClick();
//        saveData();
    }

    private void saveData() {
        JSONDBService jsondbService=  JSONDBService.getInstance(context);
        List<Object> list = jsondbService.getAll(new ArchiveBean());
        ArrayList hrs = new ArrayList<ArchiveBean>();
        if (list == null || list.size() <= 0) {
            return;
        }
        for (int i = list.size() - 1; i >= 0; i--) {
            ArchiveBean ab = (ArchiveBean) list.get(i);
            // String[] 的gettime为主键。
            hrs.add(ab);
            String name = ab.getName();
            String idcard = ab.getIdcard();
            String sex = "男".equals(ab.getSex())?"1":"2";
            Data data = new Data();
            data.setAge(10 + i);
            data.setEmpiId("234" + i);
            data.setHeight(160 + i);
            data.setIdCard(idcard);
            data.setMobileNumber("13800887900");
            data.setPersonName(name);
            data.setRegionCode("34");
            data.setRegionCode_text("RegionCode" + i);
            data.setSexCode(sex);
            data.setUid("05100031");
            List<Plan> plans = new ArrayList<Plan>();
            Plan p = new Plan();
            p.setBeginDate("2017-04-1" + i);
            p.setBusinessType("1");
            p.setEndDate("2017-04-1" + i);
            p.setPlanDate("2017-04-2" + i);
            p.setPlanId("666");
            p.setPlanStatus("1");
            p.setRecordId("1233123");
            p.setVisitId("787878");
            Plan p2 = new Plan();
            p2.setBeginDate("2017-06-1" + i);
            p2.setBusinessType("2");
            p2.setEndDate("2017-06-1" + i);
            p2.setPlanDate("2017-06-2" + i);
            p2.setPlanId("666777");
            p2.setPlanStatus("2");
            p2.setRecordId("1233123");
            p2.setVisitId("787878");
            plans.add(p);
            plans.add(p2);
            data.setPlan(plans);
            VisitPlan vp = new VisitPlan();
            try {
                vp.setJson(JsonUtil.objectToJsonStr(data).toString());
            } catch (JSONException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            vp.setIdcard("44074319930305000" + i);
            vp.setType("gxy");
            boolean b = DBService.add(vp);
            System.out.println("添加到数据库成功" + b);
        }
        for (int i = 1; i < 10; i++) {

        }
    }

    private void findView() {
        hypbtn = (Button) findViewById(R.id.btn_hypertension);
        glybtn = (Button) findViewById(R.id.btn_glycuresis);
    }

    private void setOnClick() {
        hypbtn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                intent = new Intent();
                // intent.setClass(MBGY_Main.this, HypertensionTureList.class);
                // 新的，高血压随访计划
                intent.setClass(MBGY_Main.this, GXYPlanList.class);
                startActivity(intent);
            }
        });
        glybtn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                intent = new Intent();
                // intent.setClass(MBGY_Main.this, GlycuresisTureList.class);
                // 新的，糖尿病随访计划
                intent.setClass(MBGY_Main.this, TNBPlanList.class);
                startActivity(intent);
            }
        });

    }
}